package com.ganyu.handler.exception;

import com.ganyu.domain.ResponseResult;
import com.ganyu.exception.SystemException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import static com.ganyu.enums.AppHttpCodeEnum.CAN_NOT_WATCH;
import static com.ganyu.enums.AppHttpCodeEnum.ERROR_SYSTEM;


/**
 * DATA: 2022/9/15
 * Author: 晨夕
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    //处理用户操作不当出现的异常
    @ExceptionHandler(SystemException.class)
    public ResponseResult SystemExceptionHandler(SystemException e) {
        log.error("出现了异常! {}" , e);
        return ResponseResult.errorResult(e.getCode(),e.getMsg());
    }

    //处理系统出现的异常
    @ExceptionHandler(Exception.class)
    public ResponseResult ExceptionHandler(Exception e){
        log.error("出现了异常! {}",e);
        return ResponseResult.errorResult(ERROR_SYSTEM);
    }
}
